package com.example.tys.baseapplication.View.recycleView.swipe;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.tys.baseapplication.R;
import com.example.tys.baseapplication.View.recycleView.BaseViewHolder;
import com.example.tys.baseapplication.View.recycleView.sticky.StickyAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author tys
 * @date 2017/10/14
 */

public class TestSwipeAdapter extends StickyAdapter<String, TestSwipeAdapter.VH> {
    public TestSwipeAdapter(Context context, ArrayList<String> mData) {
        super(context, mData);
    }

    @Override
    public String getItemViewTitle(int position) {
        return mData.get(position);
    }

    @Override
    public VH onCreateViewHolder(ViewGroup parent, int viewType) {
        return new VH(LayoutInflater.from(context).inflate(R.layout.swip_item_menu, null, false));
    }

    @Override
    public void onBindViewHolder(VH holder, int position) {
        holder.tv.setText(mData.get(position));
    }

    class VH extends BaseViewHolder {
        private final TextView tv;

        VH(View itemView) {
            super(itemView);
            itemView.setBackgroundColor(Color.BLUE);
            tv = (TextView) itemView.findViewById(R.id.text1);
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "content " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
                }
            });
            setOnClickListener(R.id.item_menu_delete, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "DELETE " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
                    removeData(getAdapterPosition());
                    notifyDataSetChanged();
                }
            });

            setOnClickListener(R.id.item_menu, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(context, "menu " + getAdapterPosition(), Toast.LENGTH_SHORT).show();
                }
            });

        }
    }
}
